package com.sywb.chuangyebao.view.fragment;

import android.os.Bundle;
import android.view.View;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.contract.QAndAContract;

import org.bining.footstone.rxjava.rxbus.annotation.Subscribe;
import org.bining.footstone.rxjava.rxbus.annotation.Tag;
import org.bining.footstone.rxjava.rxbus.thread.ThreadMode;

/**
 * 问答列表
 */
public class QAndAListFragment extends BaseRefreshFragment<QAndAContract.Presenter> implements QAndAContract.View {

    private int categoryId;

    /**
     * Fragment 实例
     */
    public static QAndAListFragment newInstance(Object... pramars) {
        QAndAListFragment fragment = new QAndAListFragment();
        fragment.setArguments(getBundle(pramars));
        return fragment;
    }

    @Override
    public void initView(View view, Bundle bundle) {
        super.initView(view, bundle);
        if (bundle == null) {
            categoryId = getArguments().getInt("p0", 0);
        } else {
            categoryId = bundle.getInt("p0", 0);
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        mPresenter.playStop();
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }

    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_DELETE_QUESTION)})
    public void afterDeleteQuesition(String data) {
        mPresenter.initData();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt("p0", categoryId);
        super.onSaveInstanceState(outState);
    }

    @Override
    public boolean useRxBus() {
        return false;
    }

    @Override
    public int getCategoryId() {
        return categoryId;
    }
}
